package com.tour.tour.Interceptor;

import com.tour.tour.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author YounGCY
 * @date 2023-4-29 下午 8:30
 * @description
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1.判断是否需要拦截器（ThreadLocal是否由用户
        if (UserHolder.getUser() == null) {
            response.setStatus(401);
            return false;
        }
        // 2.有用户，则放行
        return true;
        
    }
}
